var scrollObj_progressRank=null;
$( document ).on( "pagecreate", "#progressRank", function( event ) {
	$("#progressRank").on("swipeleft",function(){
		scrollObj_progressRank.destroy();
		$.mobile.changePage(rootPath+"/jsp/weixin/integralRank.jsp?access_token="+access_token);
	});
	$("#progressRank").bind("swiperight",function(){
		scrollObj_progressRank.destroy();
		 $.mobile.changePage(rootPath+"/jsp/weixin/sendFlowerRank.jsp?access_token="+access_token
				 , {transition:"slide",reverse:true}, true, true);
	});
		
	});
	$( document ).on( "pageshow", "#progressRank", function( event ) {
		access_token=getQueryString("access_token");

		pageNo="1";
		pageSize="10";
		$("#wrapper_progressRank  #pullDown").hide();
		$("#wrapper_progressRank  #pullUp").hide();
		
		scrollObj_progressRank=scrollPlugLoadedOfReturn_new("wrapper_progressRank",
				function() {
					setTimeout(function () {
						if(pageNo >= totalPage)
							return;
						pageNo++;
						loadData_progressRank(false,scrollObj_progressRank);
					}, 1000);	
				},
				function() {
					setTimeout(function () {
						if(pageNo>1){
							pageNo--;
							loadData_progressRank(true,scrollObj_progressRank);
							if(pageNo==1){
								$("#wrapper_progressRank  #pullDown").hide();
							}
						}
					}, 1000);
				});
		
		loadData_progressRank(true,scrollObj_progressRank);
	});

/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_progressRank(isFresh,scrollObj_progressRank){
	showLoading();
	$.ajax({
	  	url: rootPath+"/user/progressRank.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
		  		
				var content = "";
				for (var i=0;i<arr.length;i++){
					var headerPic=rootPath+defaultHeadPic;
					if(arr[i].headImageUrl!=undefined && arr[i].headImageUrl!="")
						headerPic=arr[i].headImageUrl;
					var toPage=rootPath+"/jsp/weixin/otherPersonInfo.jsp?access_token="+access_token+"&empId="+arr[i].empId;
					var progressStatePic="";
					var progressStatePic=integral_parallel;
					var progNum = parseInt(arr[i].ranking);
					if(progNum==0)
						progressStatePic=integral_parallel;
					else if(progNum>0)
						progressStatePic=integral_up;
					else if(progNum<0)
						progressStatePic=integral_down;
					progressStatePic=rootPath+progressStatePic;
					var bgPicClass="";
					if(arr[i].id==1)
						bgPicClass="first";
					else if(arr[i].id==2)
						bgPicClass="second";
					else if(arr[i].id==3)
						bgPicClass="thirdly";
					else
						bgPicClass="";
					
					content +='<li>\
					  <a href="#"  onClick="goTo(\''+toPage+'\')">\
					  	<span class="ui-li-desc li_one '+bgPicClass+' ">'+(arr[i].id)+'</span>\
					  	<span class="ui-li-desc li_two "><img src="'+headerPic+'"  width="40" height="40"></span>\
						<span class="ui-li-desc li_three " >'+(arr[i].empName)+'</span>\
						<span class="ui-li-desc li_four " ><img src="'+progressStatePic+'" width="40" height="40"/></span>\
						<span class="ui-li-desc li_five " ><strong>'+progNum+' 名</strong></span>\
					  </a>\
					</li>';
				}
				if(arr.length<pageSize){
					$("#wrapper_progressRank  #pullUp").hide();
				}else{
					$("#wrapper_progressRank  #pullUp").show();
				}
				if(isFresh)
					$("#thelist_progressRank").html("");
				
				//页数是2的倍数时，清空缓存列表
				if(pageNo%3==0){
					$("#wrapper_progressRank  #pullDown").show();
					$("#thelist_progressRank").html("");
					$("#thelist_progressRank").append(content).listview('refresh');
				}else{
					$("#thelist_progressRank").append(content).listview('refresh');
				}
				scrollObj_progressRank.refresh();
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}
